$ = new Object();
yqSoft = new Object();
yqSoft.ajax = new Object();
yqSoft.dom = new Object();
yqSoft.ui = new Object();

$Get = $get = yqSoft.dom.GetElement = function(Id) {
    return (typeof (Id) == "string" ? document.getElementById(Id) : Id);
}


createDelegate = function Function$createDelegate(instance, method)
{
	return function()
	{
		return method.apply(instance, arguments);
	};
};

$AjaxRequest = yqSoft.ajax.AjaxRequest = function(url, body, onSuccess) {

    alert(url);
    this.url = url;
    this.Method = "Post";
    this.Body = body ? body : "";
    this.onSuccess = onSuccess;
    //this.onError = onError;

    //异步
    this.async = true;
    //????????????????!
    this.Enctype;

    this.loadingID = null;

    if(!window.XMLHttpRequest) {
        window.XMLHttpRequest = function() {
            var progIDS = [ "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP" ];
            for(var i=0; i<progIDS.length; i++) {
                try {
                    var xmlHttp = new ActiveXObject(progIDS[i]);
                    return xmlHttp;
                }catch(ex) {

                }
            }
            return null;
        }
    }

    this.HttpRequest = new XMLHttpRequest();

    this.Start = function() {
        this.HttpRequest.onreadystatechange = createDelegate(this, this.OnReadyStateChange);
        this.HttpRequest.open(this.Method, this.url, this.async);
        if(this.Method = "Post"){
            this.HttpRequest.setRequestHeader("Content-type", this.Enctype ? this.Enctype : "application/x-www-form-urlencoded");
        }
        this.HttpRequest.send(this.Body);
        this.loading();

    }

    this.loading = function() {
        this.loadingID = mini.loading("Loading, Please wait ...", "Loading");
    }

    this.OnReadyStateChange = function()
	{
        if(this.HttpRequest.readyState == 4) {
            mini.hideMessageBox(this.loadingID);
            var result = this.HttpRequest.responseText;

            if(this.HttpRequest.status == 200) {
                var contentType = this.HttpRequest.getResponseHeader("Content-Type");
                if(contentType.indexOf("application/json") > -1) {
                    //{key: value} eval Make JavaScriptObject. Must "("+{}+")"
                    result = eval("("+result+")");
                }
                if(this.onSuccess) {
                    this.onSuccess(result);
                }
            }else {
                //调用父窗口的Mini对象
                //window.parent.mini.alert(result);
                /*mini.open({
                    url:  this.url,
                    title: "Error Messgae",
                    width: 700,
                    height:460
                });*/
                var id = this.loadingID;
                mini.open({
                    url: "/psw/common/jsp/loadingHtml.html",
                    title: "New Model", width: 700, height:460,
                    allowResize: false,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        iframe.contentWindow.SetResult(result);
                    },
                    ondestroy: function () {

                    }
                });
            }
            delete this.HttpRequest;
            this.HttpRequest = null;
        }
	};

}

/*The StringBuilder is ArrayJsObject
* new Object : new Array();
* append(item) : push
* */
function StringBuilder()
{
    this._element_ = new Array();
};
StringBuilder.prototype.append = function(item)
{
    this._element_.push(item);
};
StringBuilder.prototype.toString = function()
{
    return this._element_.join("");
};
StringBuilder.prototype.join = function(separator)
{
    return this._element_.join(separator);
};
StringBuilder.prototype.length = function()
{
    return this._element_.length;
};

/*Custom Map*/
function HashMap(){

    var struct = function(key, value) {
        this.key = key;
        this.value = value;
    }

    var put = function(key, value) {
        for(var i=0; i<this.arr.length; i++) {
            if(this.arr[i].key === key) {
                this.arr[i].value = value;
                return;
            }
        }
        this.arr[this.arr.length] = new struct(key, value);
    }

    var get = function(key) {
        for(var i=0; i<this.arr.length; i++) {
            if(this.arr[i].key === key) {
                return this.arr[i].value;
            }
        }
        return null;
    }

    var remove = function(key) {
        var v;
        for(var i=0; i<this.arr.length; i++) {
            v = this.arr.pop();
            if(v.key === key) {
                continue;
            }
            this.arr.unshift(v);
        }

    }

    var size = function() {
        return this.arr.length;
    }

    var isEmpty =function() {
        return this.arr.lengt >= 0;
    }

    this.arr = new Array();

    this.get = get;
    this.put = put;
    this.remove = remove;
    this.size = size;
    this.isEmpty = isEmpty;
}

/*Custom Equals*/
String.prototype.equals = function(str) {
    return this.toUpperCase() == str.toUpperCase();
}

/*Custom JS String TransForm DOMObject*/
function createXml(str){
     if(document.all){
        var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
        xmlDom.loadXML(str);
        return xmlDom;
     }
    else {
        return new DOMParser().parseFromString(str,"text/xml");
     }
}

/*Custom MiniAlert*/
function Mini_alert(result, method){
    mini.alert("Save Success.");
    method(result);
}







